import React , { Component , PropTypes } from 'react';

import { BrowserRouter as Router, Route, Link } from "react-router-dom";

export default class CustomLink extends Component {

    constructor( props ){
        super(props);
    }

    // static propTypes = {
    //     className:()=> PropTypes.className,
    //     exact:PropTypes.bool,
    //     preventDefault:PropTypes.bool, //阻止默认跳转
    //     onClick:PropTypes.func
    // }

    // static defaultProps = {
    //     exact:true,
    //     className:"custom",
    //     preventDefault:false,
    //     onClick:()=>{}
    // };
    enter1(nextState, replace){
        console.log('11')
    }

    render(){
        const {
            to,
            children,
            className,
            exact,
            preventDefault,
            onClick
        } = this.props;
        return (
            <Route path={to} exact={exact} children={({ match }) => {
                const clasName =  className + ( match ? ' active' : '' );
                return match || preventDefault ?
                    <div className={clasName} onClick={()=>onClick( match , to )}>
                        {children}
                    </div> :
                    <Link to={to} className={clasName}>
                        {children}
                    </Link>
            }}/>
        )
    }
};